This page last changed on May 31, 2006 by tcarlson.

As components in Mule can be plain old objects it's not always clear to the newcomer how Mule will interact with their component.

Entry Points

The entry point is the method executed by Mule when an event is received for the component. When an event is received for your component Mule dynamically chooses the method to invoke based on the payload type of the event. This means potentially your component may have many entry points. The payload type of the event is almost always determined by the inbound transformer for the provider that recieved the event for your component, but some providers such as the soap provider manage type mappings themselves so there are no need for transformers. If your component implements the Mule default event interface org.mule.umo.lifecycle.Callable this will always be called.

Event Flow

Mule has some default behavior rules about managing event flow to and from your component.

  1. When a event is received the Entrypoint method is invoked as decribed above.
  2. The response or outbound message is obtained using the following -
    1. If the method invoked is not void, (Callable.onEvent() returns an Object) the method return value is used. If null is returned no further processing is done for the current request.
    2. If the method is void, the parameters used to invoke the method are used. This assumes that the parameters themselves where altered or there was no change to the event.
  3. The outbound event is then automatically routed according the components configuration-
    1. If there is an outbound router configured, that will be invoked to route the event.
    2. If there is only a single outbound endpoint configured, that will be used.
    3. If there are multiple outbound endpoints configured, the first one will be used.

Customizing Behavior

While the default event flow behavior is sufficient, in most cases you may at some point want to customize it. To do this, you need to get a reference to the org.mule.umo.UMOEventContext. This can be done in two ways -

Implement org.mule.umo.lifecycle.Callable. The event context is passed as a parameter on this interface.

public interface Callable 
{
    public Object onCall(UMOEventContext eventContext) throws Exception;
}

You can also obtain the EventContext from the static RequestContext -

UMOEventContext context = RequestContext.getEventContext();

From the EventContext you can send and receive events synchronously and asynchronously, manage transactions and override the default event flow behavior. For example -

UMOEventContext context = RequestContext.getEventContext();
UMOEndpoint endpoint = new MuleEndpoint("jms://localhost/topic:stock.quotes");

//to send asynchronously
context.dispatchEvent(new MuleMessage("IBM:0.01", null), endpoint);

//or to receive
UMOMessage quote = context.receive(endpoint, 5000);

Even when you use the event context to manually control event flow, when your method returns, Mule will route the outbound event as normal. You can stop Mule processing events further using the following 2 methods.

1. If your service method is not void you can return null. This tells Mule there is no further event information to process.

2. If your service method is void, Mule will use the inbound event payload as the outbound event payload. If you don't want this to happen, you need to make the following call-

context.setStopFurtherProcessing(true);

Component Lifecycle

Your component can implement zero or more lifecycle interfaces, namely -

  • org.mule.umo.lifecycle.Initialisable - Is called only once for the lifecycle of the component. It is called when the component is created when the component pool initializes.
  • org.mule.umo.lifecycle.Startable - Is call when the component is started. This happens once when the server starts and whenever the component is stopped and started either through the API or JMX.
  • org.mule.umo.lifecycle.Stoppable - Is call when the component is stopped. This happens when the server stops or whenever the component is stopped either through the API or JMX.
  • org.mule.umo.lifecycle.Disposable - Is call when the component is disposed. This is caled once when the server shutsdown.

Getting the components Descriptor

A component can get a reference to its descriptor on startup by implementing org.mule.impl.UMODescriptorAware.

The UMODescriptor holds all configuration information about a component.

Document generated by Confluence on Nov 27, 2006 10:27